// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-11 12:57
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.StateCompression;

import org.junit.jupiter.api.Test;

/**
 * 求解字符串长度的最大乘积，其中两个字符串之间不能存在相同字符
 */
public class MaxProduct {
    public int maxProduct(String[] words) {
        int n = words.length, ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (diff(words[i], words[j])) {
                    ans = Math.max(ans, words[i].length() * words[j].length());
                }
            }
        }
        return ans;
    }

    private boolean diff(String s1, String s2) {
        for (char c : s1.toCharArray()) {
            if (s2.contains(c + "")) {
                return false;
            }
        }
        return true;
    }

    @Test
    public void shout() {
        String[] words = {"a","ab","abc","d","cd","bcd","abcd"};
        System.out.println(maxProduct(words));
    }
}
